package com.one.dao.impl;

import com.one.dao.booksDao;
import com.one.pojo.Books;
import com.one.utils.DBUtils;

import java.awt.print.Book;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author LJ
 * @create 2022-04-24-22:50
 */
public class bookDaoImpl implements booksDao {

    @Override
    public List<Books> allBooks() {
        List<Books> list=new ArrayList<>();
        try( Connection connection = DBUtils.getConnection()) {
            PreparedStatement preparedStatement = connection.prepareStatement("select id,bookname,price from books");
            ResultSet resultSet = preparedStatement.executeQuery();
            while (resultSet.next()){
                Books books=new Books();
                books.setId(resultSet.getInt("id"));
                books.setBookName(resultSet.getString("bookname"));
                books.setPrice(resultSet.getBigDecimal("price"));
                list.add(books);
            }
        } catch (SQLException throwables) {

            throwables.printStackTrace();
        }
        return list;
    }
}
